#include "Aenemy.hh"

Aenemy::Aenemy() {

}

Aenemy::Aenemy(const Aenemy& other) : 
    ICharacter(other),
    skill1_targets(other.skill1_targets),
    skill2_targets(other.skill2_targets),
    name(other.name),
    description(other.description),
    is_dead(other.is_dead),
    maxHealth(other.maxHealth),
    health(other.health),
    speed(other.speed),
    round_speed(other.round_speed),
    position_inteam(other.position_inteam),
    round_finsh(other.round_finsh),
    skill1_name(other.skill1_name),
    skill2_name(other.skill2_name),
    blight(other.blight),
    bleed(other.bleed),
    stun(other.stun),
    dodge(other.dodge),
    prot(other.prot) 
{}

Aenemy& Aenemy::operator=(const Aenemy& other) {
    if (this != &other) {
        ICharacter::operator=(other);
        skill1_targets = other.skill1_targets;
        skill2_targets = other.skill2_targets;
        name = other.name;
        description = other.description;
        is_dead = other.is_dead;
        maxHealth = other.maxHealth;
        health = other.health;
        speed = other.speed;
        round_speed = other.round_speed;
        position_inteam = other.position_inteam;
        round_finsh = other.round_finsh;
        skill1_name = other.skill1_name;
        skill2_name = other.skill2_name;
        blight = other.blight;
        bleed = other.bleed;
        stun = other.stun;
        dodge = other.dodge;
        prot = other.prot;
    }
    return *this;
}

bool Aenemy::isAlive() const {
    return !this->is_dead;
}

void Aenemy::takeDamage(unsigned damage) {
    damage *= 1.0 - this->prot;
    if (this->health <= damage)
    {
        this->health = 0;
        this->is_dead = true;
        this->round_finsh = true;
    } else {
        this->health -= damage;
    }
}
void Aenemy::healing(unsigned healing_amount) {
    if (this->health + healing_amount > this->maxHealth) {
        this->health = this->maxHealth;
    } else {
        this->health += healing_amount;
    }
}
// void Aenemy::takeBuff(buff_and_effect::Abuff& buff)  {
//     bool have_buff = false;
//     for (auto iterator = this->buffs.begin(); iterator != this->buffs.end(); ++iterator){
//         if(*iterator == buff){
//            *iterator += buff;
//            have_buff = true;
//            break;
//         }
//     }
//     if (!have_buff) {
//         this->buffs.push_back(buff);
//     }
// }
// void Aenemy::removeBuff(buff_and_effect::Abuff& buff) {
//     for (auto iterator = this->buffs.begin(); iterator != this->buffs.end(); ++iterator){
//         if(*iterator == buff){
//             this->buffs.erase(iterator);
//             break;
//         }
//     } 
// }

void Aenemy::modifyRoundSpeed(int new_speed) {
    this->round_speed = new_speed;
}

void Aenemy::sitRoundFinsh(bool b) {
    this->round_finsh = b;
}

void Aenemy::changePosInteam(unsigned new_pos) {
    this->position_inteam = new_pos;
}

unsigned Aenemy::getSkillName() {
    return randomFunc::get_Random_Num(1, 2);
}

unsigned Aenemy::getskill1Target() {
    return randomFunc::get_Random_Num(*this->skill1_targets.begin(), this->skill1_targets.back());
}

unsigned Aenemy::getskill2Target() {
    return randomFunc::get_Random_Num(*this->skill2_targets.begin(), this->skill2_targets.back());
}

//getter
std::string Aenemy::getName() const {
    return this->name;
}
std::string Aenemy::getDescription() const {
    return this->description;
}
unsigned Aenemy::getMaxHealth() const {
    return this->maxHealth;
}
unsigned Aenemy::getHealth() const {
    return this->health;
}
unsigned Aenemy::getSpeed() const {
    return this->speed;
}
int Aenemy::getRoundSpeed() const {
    return this->round_speed;
}
unsigned Aenemy::getPosInteam() const {
    return this->position_inteam;
}
// std::vector<buff_and_effect::Abuff> Aenemy::getBuffs() const {
//     return this->buffs;
// }
bool Aenemy::getRoundFinsh() const {
    return this->round_finsh;
}
std::string Aenemy::getskill1_name() const {
    return this->skill1_name;
}
std::string Aenemy::getskill2_name() const {
    return this->skill2_name;
}
unsigned Aenemy::getBlight() const {
    return this->blight;
}
unsigned Aenemy::getBleed() const {
    return this->bleed;
}
unsigned Aenemy::getStun() const {
    return this->stun;
}
unsigned Aenemy::getDodge() const {
    return this->dodge;
}
double Aenemy::getProt() const {
    return this->prot;
}
std::string Aenemy::toString() const {
    std::string sentens = "";
    if (!this->round_finsh) {
        sentens += "! ";
    }
    sentens += this->name + " hp: (" + std::to_string(this->health) + "/" + std::to_string(this->maxHealth) + ") speed: " + std::to_string(this->speed);
    if (this->prot > 0) {
        sentens += " prot: " + std::to_string(this->prot * 100) + "%";
    }
    // for (auto &buff : this->buffs) {
    //     sentens += buff.samllInfo();
    // }
    if (this->is_dead) {
        sentens += " (Dead body)"; 
    }
    sentens += "\n";
    return sentens;
}

Aenemy& Aenemy::operator-=(unsigned damage) {
    this->takeDamage(damage);
    return *this;
} //For taking damage
Aenemy& Aenemy::operator+=(unsigned healing_amount) {
    this->healing(healing_amount);
    return *this;
} //治疗 
